home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Info-Mac 3
/
Info_Mac_1994-01.iso
/
Development
/
Source
/
MSG Demo 1.2 Source
/
MSG Demo ƒ
/
MSG Shell ƒ
/
msg main.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-11-10
|
5KB
|
212 lines
/**********************************************************************\
File: msg main.c
Purpose: This module handles the event loop and event dispatching.
MSG Demo -- graphic effects demonstration program
Copyright (C) 1992-3 Mark Pilgrim & Dave Blumenthal
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program in a file named "GNU General Public License".
If not, write to the Free Software Foundation, 675 Mass Ave,
Cambridge, MA 02139, USA.
\**********************************************************************/
#include "msg main.h"
#include "msg integrity.h"
#include "msg graphics.h"
#include "msg menus.h"
#include "msg sounds.h"
#include "msg prefs.h"
#include "msg environment.h"
#include "demo.h"
#include "AppleEvents.h"
#include "EPPC.h"
void main(void)
{
gDone = FALSE;
MaxApplZone();
InitGraf(&thePort);
InitFonts();
FlushEvents(everyEvent, 0);
InitWindows();
InitMenus();
TEInit();
InitDialogs(0L);
InitCursor();
GetDateTime(&randSeed);
CheckEnvironment();
DoIntegrityCheck();
InitSounds();
PrefsError(PreferencesInit());
InitEnvironment();
InitProgram();
EventLoop();
ShutDownEnvironment();
ExitToShell();
}
void EventLoop(void)
{
EventRecord theEvent;
while (!gDone)
{
SetCursor(&arrow);
HiliteMenu(0);
if(gMainWindow)
SetPort(gMainWindow);
if (WaitNextEvent(everyEvent, &theEvent, 30, 0L))
DispatchEvents(theEvent);
}
}
void DispatchEvents(EventRecord gTheEvent)
{
int i;
OSErr isHuman;
Point thisPoint;
switch (gTheEvent.what)
{
case mouseDown:
HandleMouseDown(gTheEvent);
break;
case keyDown:
case autoKey:
if(gTheEvent.modifiers & cmdKey)
{
AdjustMenus();
HandleMenu(MenuKey((char)(gTheEvent.message & charCodeMask)));
}
break;
case diskEvt:
if (HiWord(gTheEvent.message)!=noErr)
{
DILoad();
SetPt(&thisPoint, 120, 120);
isHuman=DIBadMount(thisPoint, gTheEvent.message);
DIUnload();
}
break;
case updateEvt:
BeginUpdate((WindowPtr)gTheEvent.message);
if((WindowPtr)gTheEvent.message == gMainWindow)
UpdateBoard();
for (i=0; i<NUM_HELP; i++)
if ((WindowPtr)gTheEvent.message == gHelp[i])
UpdateHelp(i);
EndUpdate((WindowPtr)gTheEvent.message);
break;
case kHighLevelEvent:
if (gHasAppleEvents)
AEProcessAppleEvent(&gTheEvent);
break;
}
}
void HandleMouseDown(EventRecord gTheEvent)
{
WindowPtr theWindow;
int windowCode;
long windSize;
GrafPtr oldPort;
int i;
windowCode=FindWindow(gTheEvent.where, &theWindow);
switch (windowCode)
{
case inMenuBar:
AdjustMenus();
HandleMenu(MenuSelect(gTheEvent.where));
break;
case inContent:
if(FrontWindow() != theWindow)
SelectWindow(theWindow);
break;
case inSysWindow:
SystemClick(&gTheEvent, theWindow);
break;
case inDrag:
DragWindow(theWindow, gTheEvent.where, &gDragRect);
if(theWindow == gMainWindow)
gMainWindowBounds = (*(((WindowPeek)gMainWindow)->contRgn))->rgnBBox;
break;
case inGoAway:
if (TrackGoAway(theWindow, gTheEvent.where))
{
for (i=0; i<NUM_HELP; i++)
if (theWindow == gHelp[i])
gHelp[i]=0L;
if(theWindow == gMainWindow)
CloseMainWindow();
else
DisposeWindow(theWindow);
AdjustMenus();
}
break;
case inGrow:
gSizeRect = screenBits.bounds;
OffsetRect(&gSizeRect, gSizeRect.left, gSizeRect.top);
windSize = GrowWindow(theWindow, gTheEvent.where, &gSizeRect);
if(windSize != 0)
{
GetPort(&oldPort);
SetPort(theWindow);
EraseRect(&theWindow->portRect);
SizeWindow(theWindow, LoWord(windSize), HiWord(windSize), TRUE);
InvalRect(&theWindow->portRect);
SetPort(oldPort);
}
if(theWindow == gMainWindow)
gMainWindowBounds = (*(((WindowPeek)gMainWindow)->contRgn))->rgnBBox;
break;
case inZoomIn:
case inZoomOut:
if(TrackBox(theWindow, gTheEvent.where, windowCode))
{
GetPort(&oldPort);
SetPort(theWindow);
ZoomWindow(theWindow, windowCode, FALSE);
InvalRect(&theWindow->portRect);
SetPort(oldPort);
}
if(theWindow == gMainWindow)
gMainWindowBounds = (*(((WindowPeek)gMainWindow)->contRgn))->rgnBBox;
break;
}
}
void ShutDownEnvironment(void)
{
ShutDownProgram();
CloseSounds();
}